﻿using Castle.Windsor;
using Castle.Windsor.Configuration.Interpreters;

namespace Hippo.Core
{
    public class ServiceFactory
    {
        private static ServiceFactory instance = new ServiceFactory();
        IWindsorContainer container = new WindsorContainer(new XmlInterpreter("components.config"));

        private ServiceFactory()
        {
        }

        /// <summary>
        /// Gets the container.
        /// </summary>
        /// <value>The container.</value>
        public static IWindsorContainer Container
        {
            get { return instance.container; }
        }

        /// <summary>
        /// Gets this instance.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static T Get<T>()
        {
            return (T)instance.container[typeof(T)];
        }

        /// <summary>
        /// Gets the specified name.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="name">The name.</param>
        /// <returns></returns>
        public static T Get<T>(string name)
        {
            return (T)instance.container[name];
        }
    }
}
